#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

// https://leetcode.cn/problems/lexicographically-minimum-string-after-removing-stars/description/?envType=daily-question&envId=2025-06-07
// 3170. 删除星号以后字典序最小的字符串

class Solution {
public:
    string clearStars(string s) {
        vector<vector<int>> recordStr(26);
        for (int i = 0; i < s.size(); i++){
            if(s[i] != '*'){
                recordStr[s[i] - 'a'].push_back(i);
                continue;
            }
            for(auto & it : recordStr){
                if(!it.empty()){
                    it.pop_back();
                    break;
                }
            }
        }
        vector<int> indexArr;
        for(auto & st : recordStr){
            if(!st.empty()){
                indexArr.insert(indexArr.end(), st.begin(), st.end());
            }
        }
        std::sort(indexArr.begin(), indexArr.end());
        string ans;
        for(auto idx : indexArr){
            ans += s[idx];
        }
        return ans;
    }
};

int main()
{
    return 0;
}